package se.bth.ke.firstfriend.dto.todo.helper;

import java.util.ArrayList;
import java.util.List;
import se.bth.ke.firstfriend.model.dto.TodoInfo;

/**
 *
 * @author Markus Goetz
 */
public enum Show implements Filter {
    TODO ("todo") {
        @Override
        public List<TodoInfo> filter(List<TodoInfo> todos) {
            ArrayList<TodoInfo> selection = new ArrayList();

            for (TodoInfo todo : todos) {
                if (todo.isInProgress()) {
                    selection.add(todo);
                }
            }
            return selection;
        }
    },

    DONE ("done") {
        @Override
        public List<TodoInfo> filter(List<TodoInfo> todos) {
            ArrayList<TodoInfo> selection = new ArrayList();

            for (TodoInfo todo : todos) {
                if (todo.isDone()) {
                    selection.add(todo);
                }
            }
            return selection;
        }
    },

    ALL_BUT_DELETED ("all-but-deleted") {
        @Override
        public List<TodoInfo> filter(List<TodoInfo> todos) {
            ArrayList<TodoInfo> selection = new ArrayList();

            for (TodoInfo todo : todos) {
                if (!todo.isDeleted()) {
                    selection.add(todo);
                }
            }
            return selection;
        }
    },

    REMOVED ("removed") {
        @Override
        public List<TodoInfo> filter(List<TodoInfo> todos) {
            ArrayList<TodoInfo> selection = new ArrayList();

            for (TodoInfo todo : todos) {
                if (todo.isDeleted()) {
                    selection.add(todo);
                }
            }
            return selection;
        }
    },

    ALL ("all") {
        @Override
        public List<TodoInfo> filter(List<TodoInfo> todos) {
            return todos;
        }
    };

    private final String showString;

    private Show(String showString) {
        this.showString = showString;
    }

    public String getShowString() {
        return showString;
    }

    public static Show fromString(String showString) {
        for (Show show : Show.values()) {
            if (show.getShowString().equals(showString)) {
                return show;
            }
        }
        throw new IllegalArgumentException("Show parameter " + showString + " unknown");
    }

    @Override
    public List<TodoInfo> filter(List<TodoInfo> todos) {
        return todos;
    }
}
